<?php

namespace App\Models\System;

use App\Traits\DateTrait;
use Illuminate\Foundation\Auth\User as Authenticates;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;
use Tymon\JWTAuth\Contracts\JWTSubject;
use YangJiSen\CacheUserProvider\CacheForget;

class User extends Authenticates implements JWTSubject
{
    use HasRoles, Notifiable, DateTrait;
    protected $guard_name = 'admin';
    protected $table = 'users';
    protected $fillable = ['username', 'display_name', 'avatar', 'password', 'status', 'uuid'];
    protected $hidden = ['password', 'remember_token'];

    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims(): array
    {
        return [
            'role' => 'user'
        ];
    }

    protected static function booted()
    {
        static::saved(static function ($model) {
            CacheForget::CacheForget($model);
        });

        static::deleted(static function ($model) {
            CacheForget::CacheForget($model);
        });
    }
}
